<?php
class EditpasswordAction extends AdminAction{
	//密码修改
	Public function Index(){
		$admin=M('Admin');
		$this->display();
	}
	
	public function editing(){
		$admin=M('Admin');
		$password=trim($_POST['password']);
		$username=$_POST['username'];


		$where['username']=$username;
		$data=$admin->where($where)->field('password')->find();

		if(!$data){$this->error('用户名不存在');}
		if(empty($password)){
			$this->error('密码不能为空');
		}

		if(strlen($password)<8){
			$this->error('密码不能小于8位');
		}

		if($data['password']!=md5(trim($_POST['oldpassword']))){
			$this->error('原密码不正确');
		}

		if($password!=trim($_POST['password1'])){
			$this->error('新密码与确认新密码不一致！');
		}

		$post=array('password'=>md5(trim($password)));
		$res=$admin->where($where)->setField($post);

		if($res){
			$this->success('密码修改成功');
		}else{
			$this->error('密码修改失败');
		}
	}
}